package java3_24;

/**
 * 4：传闻StringBuilder比StringBuffer快,
 * 比较一下，输出你的比较结果（拼接10万个相同的字符串，比较时间）。
 */
public class StringHomework4 {
    public static void main(String[] args) {
        StringBuilder str1 = new StringBuilder();
        long start1 = System.nanoTime();
        for (int i = 0; i < 100000; i++) {
            str1.append("x+").append(i);
        }
        long end1 = System.nanoTime();
        System.out.println("StringBuilder:"+(end1 - start1));

        StringBuffer str2 = new StringBuffer();
        long start2 = System.nanoTime();
        for (int i = 0; i < 100000; i++) {
            str2.append("x+").append(i);
        }
        long end2 = System.nanoTime();
        System.out.println("StringBuffer:"+(end2 - start2));
    }
}
